package lock;

public class SynchronizedX {

    public static void main(String[] args) {

        Object lock = new Object();

        new Thread(() -> {
            synchronized (lock) {
                try {
                    System.out.println(Thread.currentThread().getName());
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }, "Thread-A").start();

        new Thread(() -> {
            try {
                synchronized (lock) {
                    System.out.println(Thread.currentThread().getName());
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }, "Thread-B").start();
    }
}
